/**
 * <p> Title: TSina Tweets Management and Analysis </p>
 * <p> Description: </p>
 * <p>  </p>
 *
 * <p> Institute of Massive Computing, ECNU </p>
 * <p> Copyright (c) 2010 </p>
 *
 * @author Bin Zhao
 * @version 0.9  24/11/2010
 */

package util;

import java.io.File;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class IFileWriter{
	private static final String delimiterSharp = "#";
	private static final String delimiter4Term =":";
	private static final String delimiter = " ";
	private static final String delimiterS = "\\s+";
	private FileOutputStream fos = null;
	private OutputStreamWriter osw = null;
	private BufferedWriter bw = null;
	private File fOutput = null;
	private boolean append = false;
	private String charset = "utf-8";
	
	public IFileWriter(File fOutput){
		this.fOutput = fOutput;
		this.append = false;
	}

	public IFileWriter(String charset, File fOutput){
		this.fOutput = fOutput;
		this.append = false;
		this.charset = charset;
	}

	public IFileWriter(File fOutput, boolean append){
		this.fOutput = fOutput;
		this.append = append;
	}

	public IFileWriter(File fOutput, boolean append, String charset){
		this.fOutput = fOutput;
		this.append = append;
		this.charset = charset;
	}

	public IFileWriter(File dirOutput, String fileName){
		this.fOutput = new File(dirOutput,fileName);
		this.append = false;
	}

	public IFileWriter(File dirOutput, String fileName, String charset){
		this.fOutput = new File(dirOutput,fileName);
		this.append = false;
		this.charset = charset;
	}

	public IFileWriter(File dirOutput, String fileName, boolean append){
		this.fOutput = new File(dirOutput,fileName);
		this.append = append;
	}

	public IFileWriter(File dirOutput, String fileName, boolean append, String charset){
		this.fOutput = new File(dirOutput,fileName);
		this.append = append;
		this.charset = charset;
	}

	public static void main(String []args){
		File dir = new File("/home/bzhao/Projects/tsina/data/temp");
		IFileWriter mfw = new IFileWriter(dir,"tq1est.txt");
		mfw.open();
		mfw.write("test");
		mfw.close();
	}

	public void open(){
		try{
			fos = new FileOutputStream(fOutput,append);
			osw = new OutputStreamWriter(fos,charset);
			bw = new BufferedWriter(osw);
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public void write(String line){
		try{
			bw.write(line);
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public void writeln(String line){
		try{
			bw.write(line);
			bw.newLine();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public void newLine(){
		writeln("");
	}

//	public void append(String line){
//		try{
//			bw.append(line);
//		}catch(IOException e){
//			e.printStackTrace();
//		}
//	}
//	
//	public void appendln(String line){
//		try{
//			bw.append(line);
//			bw.append("\n");
//		}catch(IOException e){
//			e.printStackTrace();
//		}
//	}
	
	public void close(){
		try{
			fos.flush();
			osw.flush();
			bw.flush();
			bw.close();
			osw.close();
			fos.close();
		}catch(IOException e){
			e.printStackTrace();
		}
	}//*/
}

